﻿using Kang.DbDoc.Abstracts;
using Kang.DbDoc.Interfaces;
using Kang.DbDoc.Models;
using Kang.ExtendMethod;
using MySql.Data.MySqlClient;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Kang.DbDoc.ServicesImpl
{
    public class PostgreSQLConnectionService : BaseConnection, IConnectionService
    {
        public string GetConnectionString(DatabaseModel databaseModel)
        {
            var npgsqlBuilder = new NpgsqlConnectionStringBuilder();
            npgsqlBuilder.Host = databaseModel.DatabaseHost;
            npgsqlBuilder.Port = databaseModel.DatabasePort;
            npgsqlBuilder.Database = databaseModel.DatabaseName;
            npgsqlBuilder.Username = databaseModel.DatabaseUsername;
            npgsqlBuilder.Password = databaseModel.DatabasePassword;
            npgsqlBuilder.CommandTimeout = databaseModel.TimeOut;
            npgsqlBuilder.PersistSecurityInfo = true;
            return npgsqlBuilder.ToString();
        }

        public void SetDefault(DatabaseModel databaseModel)
        {
            databaseModel.DatabasePort = 5432;
            databaseModel.DatabaseUsername = "postgres";
            if (databaseModel.DatabaseHost.IsBlank())
            {
                databaseModel.DatabaseHost = "127.0.0.1";
            }
        }

        public void LoadDatabaseData(DatabaseModel databaseModel, string SearchWord)
        {
            App.ShowMessageAsync("提示", "目前仅支持SqlServer、MySQL，其它数据库正在开发中！");
        }
    }
}
